import basePanleScript from "../../base/basePanleScript";
import gameModel from "./gameModel";
import AudioUtils from "../AudioUtils";

const { ccclass, property } = cc._decorator;

@ccclass
export default class overGame extends basePanleScript {
    public onLoaded(param: any): void {
        // throw new Error("Method not implemented.");
    }
    public onEnter(param: any): void {
        // throw new Error("Method not implemented.");
    }
    public onRefresh(param: any): void {
        // throw new Error("Method not implemented.");
    }

    handler(data){}

    switchEvent(event){
        var btnName=event.target.name;
        switch(btnName){
            case 'btn_home':
                console.log("回到主界面");
                (<any>window).CustomEventManager.trigger({type:"jumpScene",content:{sceneName:"mainScene"}})
            break;
            case 'btn_share':
                console.log("分享")
                this.showToast("暂未开放")
            break;
            case 'btn_ranking':
                console.log("排行榜")
                this.showToast("暂未开放")
            break;
            case 'btn_playAgian':
                console.log("重玩");
                (<any>window).CustomEventManager.trigger({type:"gameState",content:{state:"startGame"}})
            break;
        }
        AudioUtils.getInstance().playEffect("button.wav")
    }
    
    onEnable(){
        AudioUtils.getInstance().playBgMusic("overMusic.mp3");
        this._get_("scoreLabel",cc.Label).string=gameModel.getInstance().Score;
        this.node.on(cc.Node.EventType.TOUCH_END,this.switchEvent,this,true)
    }
    onDisable(){
        console.error("overGame被销毁了吗")
        this.node.off(cc.Node.EventType.TOUCH_END,this.switchEvent,this,true)
    }


}
